package com.zjw.zy.componse.demo.manager

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.zjw.zy.componse.demo.MainActivity
import com.zjw.zy.componse.demo.R
import com.zjw.zy.componse.demo.base.BaseComposeFragment

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/9/28 16:17
 */
object PageManager {
    private const val TAG = "PageManager"
    private var sRoot: Fragment? = null
    private var sFragmentManager: FragmentManager? = null
    fun init(mainActivity: MainActivity) {
        sRoot = mainActivity.supportFragmentManager.findFragmentById(R.id.nav_host_main)
        if (sRoot == null) {
            throw RuntimeException("sRoot == null")
        }
        sFragmentManager = sRoot!!.childFragmentManager
    }

    val topFragment: BaseComposeFragment?
        get() {
            if (sRoot == null) {
                throw RuntimeException("sRoot == null")
            }
            return sFragmentManager!!.primaryNavigationFragment as BaseComposeFragment?
        }
}